// PathFinder.h

#pragma once
#include "TrainNet.h"
#include "queue"

using namespace std;

class PathFinder
{
private:
	Station*	m_InitialStation;
	Station*	m_TargetStation;
	State*		m_InitialState;
	State*		m_TargetState;
	TrainNet*		m_Net;
	double		m_SecondsPerCount;
	double		m_TotalCalculationTime;
	bool		m_bSearchBidirectional;
	bool		m_bFoundSolution;
	long long	BeginTime;
	long long	EndTime;

public:
				PathFinder();

	void		SetInitialStation(Station* InitialStation);
	void		SetTargetStation(Station* TargetStation);
	void		SetNet(TrainNet* Net);

	bool		FindFastestRouteBi();
	bool		FindFastestRoute(Station* InitialStation, Station* TargetStation);
	bool		FindFastestRoute();

	string		GetPath();
	void		SetBidirectional(bool bBidirectional);

private:
	State*		CreateInitialState(bool bBackward=false);
	bool		IsTargetState(State* State);
	void		TravelThroughPath();
	void		RemoveInitialChangeOfLines();
	void		ResetStates();
	void		StartTimer();
	void		StopTimer();
	void		FinalizeOutput();
	void		ResolveBidirectionalSearch(priority_queue<State*,vector<State*>,StateForwardPriorityComparator>& OpenA,
											priority_queue<State*,vector<State*>,StateBackwardPriorityComparator>& OpenB, State* x);
};